<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib  prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="redis" uri="http://www.shopjsp.com/redisTag/functions" %>
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<c:set var="basePath" value="${redis:getSysConfig('base_path_back')}"/>
<script type="text/javascript">
    /**
     * 自定义验证规则
     */
    function validateForm(){
        form.bootstrapValidator({
            message: "无效的值",
            feedbackIcons: {
                valid: "glyphicon glyphicon-ok",
                invalid: "glyphicon glyphicon-remove",
                validating: "glyphicon glyphicon-refresh"
            },
            fields: {
                cityCourierName: {
                    validators: {
                        notEmpty: {message: "姓名(账号)不可为空"},
                        stringLength: {max: 20,message: "姓名(账号)最大长度为20"},
                        regexp: {
                            regexp: validateUtil.chinese,
                            message: '姓名为汉字'
                        }
                    }
                },
                province: {
                    validators: {
                        notEmpty: {message: "请选择省份"}
                    }
                },
                cities: {
                    validators: {
                        notEmpty: {message: "请选择城市"}
                    }
                },
                district: {
                    validators: {
                        notEmpty: {message: "请选择区县"}
                    }
                },
                phone: {
                    validators: {
                        notEmpty: {message: "手机号不可为空"},
                        stringLength: {max: 20,message: "手机号最大长度为20"},
                        regexp: {
                            regexp: validateUtil.phone,
                            message: '请输入有效的联系电话'
                        }
                    }
                },
                address: {
                    validators: {
                        notEmpty: {message: "联系地址不可为空"},
                        stringLength: {min: 2,max: 100,message: "联系地址长度为2至100"}
                    }
                },
                cardIdNo: {
                    validators: {
                        notEmpty: {message: "身份证号不可为空"},
                        stringLength: {min: 10,max: 20,message: "身份证号长度为10至20"},
                        regexp: {
                            regexp:validateUtil.IDCard,
                            message: '请输入有效的身份证号'
                        }
                    }
                },
                introducer: {
                    validators: {
                        stringLength: {min: 2,max: 20,message: "介绍人长度为2至20"},
						regexp: {
							regexp: validateUtil.chinese,
								message: '介绍人为汉字'
						}
                    }
                }
            }
        });
    }

    /**
     * 添加同城快递信息
     */
	<shiro:hasPermission name="back_gotoCityCourierPage_add">
	function addInfo(){
        $("#myModalLabel").empty().text("添加同城快递信息");
        /**清空隐藏域的值**/
        $("#cityCourierId").val("");
        $("#responsibleAreas").val("");
        resetAddForm();
    }
    </shiro:hasPermission>

    /**
     * 编辑同城快递信息
     */
	<shiro:hasPermission name="back_gotoCityCourierPage_update">
    function editInfo(){
        $("#myModalLabel").empty().text("修改同城快递信息");
        /**获取选中行的id**/
        var selectedRow= $("#tt").bootstrapTable('getSelections');
        if(selectedRow.length==1){
            var id=selectedRow[0].cityCourierId;
            $("#btn_edit").attr("data-target","#addOrEditModal");/**选中了记录后才可打开对应的模态框**/
            $.ajax({
                type: "POST",
                dataType: "JSON",
                url: "${basePath}/back/cityCourier/getCityCourierInfo.sjson",
                data: {id:id},
                success: function(result){
                    var data = JSON.parse(result.data);
                    var cityCourier=data.cityCourier;
                    var cityList=data.cityList;
                    var districtList=data.districtList;
                    /**隐藏域**/
                    $("#cityCourierId").val(cityCourier.cityCourierId);
                    $("#responsibleAreas").val(cityCourier.responsibleAreas);
                    /**可见表单控件**/
                    $("#cityCourierName").val(cityCourier.cityCourierName);
                    $("#phone").val(cityCourier.phone);
                    $("#address").val(cityCourier.address);
                    $("#cardIdNo").val(cityCourier.cardIdNo);
                    $("#entryTime").val(new Date(data.cityCourier.entryTime).Format("yyyy-MM-dd"));/**使用转换过的时间entryTime**/
                    $("#introducer").val(cityCourier.introducer);
                    var area=cityCourier.responsibleAreas.split(",");
                    $("#province").val(area[0]);
                    var citiesOption="<option value=''>--请选择--</option>";
                    for(var i=0;i<cityList.length;i++){
                        citiesOption+="<option  value='" + cityList[i].areaId+"'>" + cityList[i].name+ "</option>";
                    }
                    $("#cities").html(citiesOption);
                    var districtOption="<option value=''>--请选择--</option>";
                    for(var i=0;i<districtList.length;i++){
                        districtOption+="<option  value='" + districtList[i].areaId+"'>" + districtList[i].name+ "</option>";
                    }
                    $("#district").html(districtOption);
                    $("#cities").val(area[1]);
                    $("#district").val(area[2]);
                }
            });
        }else{
            $("#btn_edit").attr("data-target", "");/**没有选中记录不可打开模态框**/
            showMsg("请选择一行记录！");
        }
    }
    </shiro:hasPermission>
</script>
<!--添加编辑模态框（Modal） -->
<div class="modal fade" id="addOrEditModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" data-backdrop="static" >
	<div class="modal-dialog" style="width:70%">
		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
				<h5 class="modal-title" id="myModalLabel"></h5>
			</div>
			<div class="modal-body">
				<form id="form1"  method="post" action="${basePath}/back/cityCourier/saveOrUpdateCityCourier.sjson">
					<input id="cityCourierId" type="hidden" name="cityCourierId" noclear="true"/>
					<input id="responsibleAreas" type="hidden" name="responsibleAreas" noclear="true"/>
					<table align="center" class="addOrEditTable table-bordered table" style="width:100%;">
						<tr>
							<td class="toright_td" width="150px"><span style="color:red">* </span>姓名(账号):&nbsp;&nbsp;</td>
							<td  class="toleft_td" colspan="3">
								<div class="form-group">
									<input type="text" class="form-control input-sm" id="cityCourierName" name="cityCourierName" placeholder="请输入姓名(账号)"/>
								</div>
							</td>
						</tr>
						<tr>
							<td class="toright_td" width="150px"><span style="color:red">* </span>责任区域:&nbsp;&nbsp;</td>
							<td  class="toleft_td" width="220px" style="border-right: none;">
								<div class="form-group">
									<select id="province" name="province" onchange="changeArea(this.value,'1','addOrEdit')" class="form-control input-sm">
										<option value="">请选择省份</option>
										<c:forEach  items="${provinceList}" var="first">
											<option  value="${first.areaId}">${first.name}</option>
										</c:forEach >
									</select>
								</div>
							</td>
							<td  class="toleft_td" width="220px" style="border-left: none;border-right: none;">
								<div class="form-group">
									<select id="cities" name="cities" onchange="changeArea(this.value,'2','addOrEdit')" class="form-control input-sm">
										<option value="">请选择城市</option>
									</select>
								</div>
							</td>
							<td  class="toleft_td" width="220px" style="border-left: none;">
								<div class="form-group">
									<select id="district"  name="district" class="form-control input-sm">
										<option value="">请选择区(县)</option>
									</select>
								</div>
							</td>
						</tr>
						<tr>
							<td class="toright_td" width="150px"><span style="color:red">* </span>手机号:&nbsp;&nbsp;</td>
							<td  class="toleft_td" colspan="3">
								<div class="form-group">
									<input type="text" class="form-control input-sm" id="phone" name="phone" placeholder="请输入手机号"/>
								</div>
							</td>
						</tr>
						<tr>
							<td class="toright_td" width="150px"><span style="color:red">* </span>联系地址:&nbsp;&nbsp;</td>
							<td  class="toleft_td" colspan="3">
								<div class="form-group">
									<input type="text" class="form-control input-sm" id="address" name="address" placeholder="请输入联系地址"/>
								</div>
							</td>
						</tr>
						<tr>
							<td class="toright_td" width="150px"><span style="color:red">* </span>身份证号:&nbsp;&nbsp;</td>
							<td  class="toleft_td" colspan="3">
								<div class="form-group">
									<input type="text" class="form-control input-sm" id="cardIdNo" name="cardIdNo" placeholder="请输入身份证号"/>
								</div>
							</td>
						</tr>
						<tr>
							<td class="toright_td" width="150px"><span style="color:red">* </span>入职时间:&nbsp;&nbsp;</td>
							<td  class="toleft_td" colspan="3">
								<div class="input-group date form_datetime col-md-5" data-link-field="dtp_input1">
									<input id="entryTime" name="entryTime" class="form-control" size="16" type="text" value="" placeholder="请输入入职时间" style="font-size: 12px;" readonly>
									<span class="input-group-addon"><span class="glyphicon glyphicon-remove"></span></span>
									<span class="input-group-addon"><span class="glyphicon glyphicon-th"></span></span>
								</div>
								<script type="text/javascript">
									$('.form_datetime').datetimepicker({format: "yyyy-MM-dd",language:'zh-CN',weekStart:1, todayBtn:1,autoclose: 1,todayHighlight: 1,startView: 2, minView: 2, forceParse: 0});
								</script>
							</td>
						</tr>
						<tr>
							<td class="toright_td" width="150px">介绍人:&nbsp;&nbsp;</td>
							<td  class="toleft_td" colspan="3">
								<div class="form-group">
									<input type="text" class="form-control input-sm" id="introducer" name="introducer" placeholder="请输入介绍人"/>
								</div>
							</td>
						</tr>
					</table>
				</form>
			</div>
			<div class="modal-footer">
				<button type="button" id="validateBtn" class="btn btn-primary"  onclick="submitForm()">保存</button>
				<button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
			</div>
		</div><!-- /.modal-content -->
	</div><!-- /.modal -->
</div>
